package com.example.demo;

import com.example.demo.po.WiselyResponse;
import com.example.demo.service.WebSocketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import sun.rmi.log.LogInputStream;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * 功能描述:模拟服务器给页面推送数据__测试
 * 版本信息:   Copyright (c)2018
 * 公司信息:   杭州佐通科技有限公司
 * 开发人员:   xiaohuang
 * 联系:   331088675@qq.com
 * 创建日期:   2018/9/13 14:57
 * 时间         开发者      版本号    修改内容
 * ------------------------------------------------------------------
 * 2018/9/13    xiaohuang      1.0         1.0 Version
 */
@Configuration
@Component
@EnableScheduling
public class MaintainQueryToUpdate {
    //@Reference(version = MaintainService.VERSION)
    private  static  final Logger logger= LoggerFactory.getLogger(MaintainQueryToUpdate.class);
    //String stringBuffer="";
    //int x=0;
    //private DataMapper dataMapper;
    //0 0 0/1 * * ?每过一小时执行一次
    //@Autowired
    //ApplicationContext springContext = SpringContextUtil.getApplicationContext();
    //private MaintainMapper maintainMapper;
    //@Autowired
    //@Resource
    //MaintainServiceImpl maintainService=new MaintainServiceImpl();
    //protected MaintainService maintainService =(MaintainService)springContext.getBean(MaintainService.class);
    @Scheduled(cron = "0/5 * * * * ?")//每分钟查询一次
    public void queryMaintain(){
        ApplicationContext applicationContext = SpringContextUtil.getApplicationContext();
        WebSocketService webSocketService = (WebSocketService)applicationContext.getBean("webSocketService");
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String time = LocalDateTime.now().format(dateTimeFormatter);
        List<String> list=new ArrayList();
        list.add("d892bf12bf7d11e793b69c5c8e6f60fb");
        WiselyResponse WiselyResponse=new WiselyResponse("123");
        WiselyResponse.setResponseMessage(time);
        webSocketService.send2Users(list,WiselyResponse);
        //logger.info("每分钟执行一次查询==========================================");
        System.out.println("开启线程-----------------------"+webSocketService);

    }
}
